package cn.his.medical.phismange.app;

import android.app.Application;
import android.nfc.Tag;
import android.os.Handler;
import android.os.Looper;


import java.util.logging.LogRecord;

import cn.his.medical.phismange.BuildConfig;
import cn.his.medical.phismange.app.Exception.ExceptionAdapter;

/**
 * 作者：xiewei on 2018/3/15 11:44
 * 邮箱：xiewei19910115@163.com
 */
public class App extends Application {
    private static final String TAG = App.class.getSimpleName(); //返回原始类的名称   匿名函数就返回空
    private static App instance ;
    private static boolean isDebug;

    /**
     * looper.myLooper()  获取当前线程
     * Looper.getMainLooper () 获得UI线程的Lopper
     */
    private static Handler handler = new Handler(Looper.getMainLooper());

    private static boolean isMainProcess = false;
    public static Handler getHandler(){
        return handler;
    }
    public static  boolean getIsDebug(){
       return isDebug;
    }
    public static App getInstance(){
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        if (instance == null){
            instance = this;
            return;
        }
        instance = this;
        isDebug = setDebugMode();
        initException();
    }
    //debug调试时捕获异常
    private void initException() {
        if (isDebug){
            Thread.UncaughtExceptionHandler handlers = Thread.getDefaultUncaughtExceptionHandler();
            ExceptionAdapter exceptionAdapter = new ExceptionAdapter(handlers);
            Thread.setDefaultUncaughtExceptionHandler(exceptionAdapter);
        }else{
            try {
                //TODO 可以上传到某个地方
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

    private boolean setDebugMode() {
        return BuildConfig.DEBUG;
    }

}
